package com.ruoyi.Plancontent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Plancontent.domain.StudyPlancontent;
import com.ruoyi.Plancontent.service.IStudyPlancontentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 复习计划存储Controller
 * 
 * @author luobom
 * @date 2021-12-10
 */
@RestController
@RequestMapping("/Plancontent/Plancontent")
public class StudyPlancontentController extends BaseController
{
    @Autowired
    private IStudyPlancontentService studyPlancontentService;


    /**
     * 清空状态
     * @return
     */
    @GetMapping("/mainisnothing")
    public AjaxResult mainisnothing(StudyPlancontent studyPlancontent)
    {
        return AjaxResult.success(studyPlancontentService.mainisnot("yes"));
    }
    /**
     * 查询复习计划存储列表
     */
//    @PreAuthorize("@ss.hasPermi('Plancontent:Plancontent:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudyPlancontent studyPlancontent)
    {
        startPage();
        List<StudyPlancontent> list = studyPlancontentService.selectStudyPlancontentList(studyPlancontent);
        return getDataTable(list);
    }

    /**
     * 导出复习计划存储列表
     */
    @PreAuthorize("@ss.hasPermi('Plancontent:Plancontent:export')")
    @Log(title = "复习计划存储", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudyPlancontent studyPlancontent)
    {
        List<StudyPlancontent> list = studyPlancontentService.selectStudyPlancontentList(studyPlancontent);
        ExcelUtil<StudyPlancontent> util = new ExcelUtil<StudyPlancontent>(StudyPlancontent.class);
        util.exportExcel(response, list, "复习计划存储数据");
    }

    /**
     * 获取复习计划存储详细信息
     */
    @GetMapping(value = "/{uid}")
    public AjaxResult getInfo(@PathVariable("uid") String uid)
    {
        return AjaxResult.success(studyPlancontentService.selectStudyPlancontentByUid(uid));
    }

    /**
     * 新增复习计划存储
     */
    @Log(title = "复习计划存储", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudyPlancontent studyPlancontent)
    {
        if(studyPlancontent.getEmail()==null){
            studyPlancontent.setEmail("false");
        }
        return toAjax(studyPlancontentService.insertStudyPlancontent(studyPlancontent));
    }

    /**
     * 修改复习计划存储
     */
    @Log(title = "复习计划存储", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudyPlancontent studyPlancontent)
    {
        return toAjax(studyPlancontentService.updateStudyPlancontent(studyPlancontent));
    }

    /**
     * 删除复习计划存储
     */
    @Log(title = "复习计划存储", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uids}")
    public AjaxResult remove(@PathVariable String[] uids)
    {
        return toAjax(studyPlancontentService.deleteStudyPlancontentByUids(uids));
    }
}
